package com.sourcestream.whileaway;

import android.content.ComponentName;
import android.content.Context;
import android.content.pm.PackageManager;

public class ReceiverManager
{
    public static void enableReceiver(Context context, Class clazz)
    {
        ComponentName componentName = new ComponentName(context, clazz);

        context.getPackageManager().setComponentEnabledSetting(componentName,
            PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
    }

    public static void disableReceiver(Context context, Class clazz)
    {
        ComponentName componentName = new ComponentName(context, clazz);

        context.getPackageManager().setComponentEnabledSetting(componentName,
            PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
    }

    public static boolean isReceiverDisabled(Context context, Class clazz)
    {
        ComponentName component = new ComponentName(context, clazz);

        return context.getPackageManager().getComponentEnabledSetting(component) ==
            PackageManager.COMPONENT_ENABLED_STATE_DISABLED;
    }
}
